package com.sayp.netdisk.controller;

import com.sayp.netdisk.pojo.File;
import com.sayp.netdisk.pojo.User;
import com.sayp.netdisk.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("file")
public class MoveController {
    @Autowired
    private FileService fileService;
    @Autowired
    private UserController userController;
    /**
     * 移动文件
     * @param fid 待移动文件id
     * @param targetId 目标目录id
     * @return
     */
    @PutMapping("/move/{fid}/{targetId}")
    public boolean moveFile(@PathVariable("fid") int fid, @PathVariable("targetId") int targetId, HttpSession session){
        User user = userController.getUserInfo(session);
        if(user==null)return false;
        return fileService.moveFile(fid, targetId, user.getUid());
    }


    /**
     * 获取所有文件目录结构
     * @return
     */
    @GetMapping("/getStructure")
    public File getFileStructure(HttpSession session){
        User user = userController.getUserInfo(session);
        if(user==null)return null;
        return fileService.findFileStructure(user.getUid());
    }


}
